/*
 * \brief  Client-side interface for PCI device
 * \author Norman Feske
 * \date   2008-01-28
 */

/*
 * Copyright (C) 2008-2009 Norman Feske
 * Genode Labs, Feske & Helmuth Systementwicklung GbR
 *
 * This file is part of the Genode OS framework, which is distributed
 * under the terms of the GNU General Public License version 2.
 */

#ifndef _INCLUDE__PCI_DEVICE__CLIENT_H_
#define _INCLUDE__PCI_DEVICE__CLIENT_H_

#include <pci_session/pci_session.h>
#include <pci_device/pci_device.h>

namespace Pci {

	class Device_client : public Device
	{
		private:

			Genode::Msgbuf<64> _snd_msg, _rcv_msg;
			Genode::Ipc_client _ipc_client;

		public:

			/**
			 * Constructor
			 */
			Device_client(Device_capability device)
			: _ipc_client(device, &_snd_msg, &_rcv_msg) { }


			/**************************
			 ** PCI device interface **
			 **************************/

			unsigned short vendor_id()
			{
				unsigned short result = 0;
				_ipc_client << VENDOR_ID << Genode::IPC_CALL >> result;
				return result;
			}

			unsigned short device_id()
			{
				unsigned short result = 0;
				_ipc_client << DEVICE_ID << Genode::IPC_CALL >> result;
				return result;
			}

			unsigned class_code()
			{
				unsigned result = 0;
				_ipc_client << CLASS_CODE << Genode::IPC_CALL >> result;
				return result;
			}

			Resource resource(int resource_id)
			{
				Resource result;
				_ipc_client << RESOURCE << resource_id
				            << Genode::IPC_CALL >> result;
				return result;
			}

			unsigned config_read(unsigned char address, Access_size size)
			{
				unsigned result = ~0;

				_ipc_client << CONFIG_READ << address << size
				            << Genode::IPC_CALL >> result;
				return result;
			}

			void config_write(unsigned char address, unsigned value, Access_size size)
			{
				_ipc_client << CONFIG_WRITE << address << value << size
				            << Genode::IPC_CALL;
			}
	};
}

#endif /* _INCLUDE__PCI_DEVICE__CLIENT_H_ */
